package com.web.surf.sample.eshop.faces.backing.beans;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.web.surf.sample.eshop.database.manager.interfaces.IFeaturesService;
import com.web.surf.sample.eshop.faces.interfaces.IRedirect;
import com.web.surf.sample.eshop.utils.FacesUtil;

public class GoodsFeatures{

	private Map<String, String> features;
	private IFeaturesService featuresService;	
	private Integer goodsID;

	public Map<String, String> getFeatures() {
		if (features == null) {
			loadFeatures();
		}
		return features;
	}

	private void loadFeatures() {
		goodsID = Integer.parseInt((String) FacesUtil
				.getSessionMapValue(IRedirect.REDIRECT_LINK));
		features = getFeaturesService().getFeaturesByID(goodsID);
	}

	public List<String> getFeatureNames() {
		loadFeatures();
		List<String> names = new ArrayList<String>();
		for (String s : features.keySet()) {
			names.add(s);
		}
		return names;
	}

	public IFeaturesService getFeaturesService() {
		return featuresService;
	}
	
	//Spring	
	public void setFeaturesService(IFeaturesService featuresService) {
		this.featuresService = featuresService;
	}

}